from django.forms.models import modelformset_factory
from django.shortcuts import render_to_response as r2r

from forms.models import Form


def index(request):
    latest_form_list = Form.objects.all().order_by('-start_pub')
    return r2r('forms/index.html', {'latest_form_list': latest_form_list})

def detail(request, form_id):
    FormSet = modelformset_factory(Form, extra=0)
    f = FormSet(queryset=Form.objects.filter(id=form_id))
    return r2r('forms/detail.html', {'form': f})